package com.world.lzh.controller;

import com.world.lzh.entity.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @version 1.0
 * @Author lzh
 * @Date 2022/4/26 - 19:45
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @PostMapping("/")
    public String insertUser(@Valid User user, BindingResult bindingResult) {
        StringBuffer stringBuffer = new StringBuffer();
        if (bindingResult.hasErrors()) {
            List<ObjectError> list = bindingResult.getAllErrors();
            for (ObjectError objectError : list) {
                stringBuffer.append(objectError.getDefaultMessage());
                stringBuffer.append("/---/");
            }
        }
        return stringBuffer.toString();
    }
}
